//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#include <buola/buola.h>
#include <buola/io.h>

using namespace buola;

void PrintURI(const io::CURI &pURI)
{
    msg_info() << "url:[" << pURI.ToString() << "]\n";
    msg_info() << "  scheme:[" << pURI.SchemeName() << "]\n";
    msg_info() << "  user:[" << pURI.User() << "]\n";
    msg_info() << "  pass:[" << pURI.Pass() << "]\n";
    msg_info() << "  host:[" << pURI.Host() << "]\n";
    msg_info() << "  port:[" << pURI.Port() << "]\n";
    msg_info() << "  folder:[" << pURI.Folder() << "]\n";
    msg_info() << "  name:[" << pURI.Name() << "]\n";
    msg_info() << "  path:[" << pURI.Path() << "]\n";
    msg_info() << "  query:[" << pURI.Query() << "]\n";
    msg_info() << "  fragment:[" << pURI.Fragment() << "]\n";

    std::map<std::string,std::string> lItems=pURI.GetQueryItems();
    msg_info() << "  query items:\n";
    for(auto lIt=lItems.begin();lIt!=lItems.end();++lIt)
    {
        msg_info() << "    " << lIt->first << " = " << lIt->second << "\n";
    }
    msg_info() << "\n";
}

int main()
{
    PrintURI(io::file("home/xavi/tonto.cc"));
    PrintURI(io::uri("http://xavi@buola.org/tonto"));
    PrintURI(io::uri("http://xavi@buola.org:80/tonto"));
    PrintURI(io::uri("http://www.google.com:8080/"));
    PrintURI(io::uri("http://xavi@buola.org/tonto?info=3&info2=4"));
    PrintURI(io::uri("http://xavi@buola.org/tonto?info=3&info2=number%20with%20spaces#four"));
    PrintURI(io::uri("http://xavi:pass@buola.org/tonto#three"));
    PrintURI(io::uri("buola.org/tonto"));
    io::CURI lURI=io::uri("http://www.buola.org/home/xavi#three");
    PrintURI(lURI);
    lURI.AddQueryItem("tonto","value 3");
    PrintURI(lURI);
    lURI.AddQueryItem("tonto 2","value 4");
    PrintURI(lURI);
    lURI.AddQueryItem("tonto","value 5");
    PrintURI(lURI);

    PrintURI(io::uri("file:///home/tonto"));
    PrintURI(io::uri("file://home/tonto"));
    PrintURI(io::uri("file:///home/xavi?tonto#three"));
    PrintURI(io::file("~/tonto"));

    return 0;
}
